package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.entity.Sale;
import com.qf.enums.JxcEnum;
import com.qf.service.SaleService;
import com.qf.util.R;
import com.qf.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 作者: 王鑫
 * 项目名: jxc2
 * 时间:2019/12/5  9:45
 * 描述:
 */
@RestController
@RequestMapping("/sale")
public class SaleController {
    @Autowired
    private SaleService saleService;
    @RequestMapping("/add")
    public ResultVo add(Sale sale){

        int i = saleService.insert(sale);

        if (i != 0){
            return R.ok();
        }else {
            return R.error(JxcEnum.CODE_ERROR);
        }
    }


/*
    分页查询销售记录并排序
``
路径
GET		http://localhost/sale/list
``
    参数
            currentPage=1
    pageSize=5
    flag=0			// 根据flag指定排序方式
            ``
响应数据
	成功
		{
			"code":0,
			"msg":"成功",
			"data":
				{
					"currentPage" : 1,
					"pageSize" : 5,
					"totalCount" : 9,
					"totalPage" : 2,
					"list" : [
						{
							"id":1,
							"price":10.2,
							"quantity":10,
							"totalprice":102,
							"saledate":1233812687,
							"productName":"汤圆",
							"realName":"詹姆斯"
						},
						..
					]
				}
		}
	失败
		{
			"code":错误编码,
			"msg":"错误信息",
			"data":null
		}*/

    @RequestMapping("/list")
    public ResultVo list(Integer pageNum,Integer pageSize,@RequestParam(defaultValue = "2") Integer flag){

        PageInfo<Sale> pageInfo = saleService.list(pageNum,pageSize,flag);
        return R.ok(pageInfo);
    }



}
